home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / system-config-printer / installpackage.py < prev    next >
Encoding:
Python Source  |  2009-05-05  |  2.6 KB  |  72 lines

  1. #!/usr/bin/env python
  2.  
  3. ## system-config-printer
  4.  
  5. ## Copyright (C) 2008 Red Hat, Inc.
  6. ## Copyright (C) 2008 Tim Waugh <twaugh@redhat.com>
  7.  
  8. ## This program is free software; you can redistribute it and/or modify
  9. ## it under the terms of the GNU General Public License as published by
  10. ## the Free Software Foundation; either version 2 of the License, or
  11. ## (at your option) any later version.
  12.  
  13. ## This program is distributed in the hope that it will be useful,
  14. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ## GNU General Public License for more details.
  17.  
  18. ## You should have received a copy of the GNU General Public License
  19. ## along with this program; if not, write to the Free Software
  20. ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. import dbus
  23. import xml.etree.ElementTree
  24. from dbus.mainloop.glib import DBusGMainLoop
  25. DBusGMainLoop (set_as_default=True)
  26.  
  27. class PackageKit:
  28.     def __init__ (self):
  29.         bus = dbus.SessionBus ()
  30.         obj = bus.get_object ("org.freedesktop.PackageKit",
  31.                               "/org/freedesktop/PackageKit")
  32.  
  33.         # Find out which API is required.
  34.         num_args = -1
  35.         introsp = dbus.Interface (obj, "org.freedesktop.DBus.Introspectable")
  36.         api = introsp.Introspect ()
  37.         top = xml.etree.ElementTree.XML (api)
  38.         for interface in top.findall ("interface"):
  39.             if interface.attrib.get ("name") != "org.freedesktop.PackageKit":
  40.                 continue
  41.  
  42.             for method in interface.findall ("method"):
  43.                 if method.attrib.get ("name") != "InstallPackageName":
  44.                     continue
  45.  
  46.                 num_args = len (method.findall ("arg"))
  47.                 break
  48.  
  49.         if num_args == -1:
  50.             raise RuntimeError, "Introspection failed for PackageKit"
  51.  
  52.         self.proxy = dbus.Interface (obj, "org.freedesktop.PackageKit")
  53.         self.num_args = num_args
  54.  
  55.     def InstallPackageName (self, xid, timestamp, name):
  56.         proxy = self.proxy
  57.         if self.num_args == 3:
  58.             return proxy.InstallPackageName (xid, timestamp, name,
  59.                                              reply_handler=self.reply_handler,
  60.                                              error_handler=self.error_handler)
  61.         else:
  62.             # Old PackageKit interface
  63.             return proxy.InstallPackageName (name,
  64.                                              reply_handler=self.reply_handler,
  65.                                              error_handler=self.error_handler)
  66.  
  67.     def reply_handler (self, *args):
  68.         pass
  69.  
  70.     def error_handler (self, *args):
  71.         pass
  72.